package com.test.dababy.dababy_05_process.widget;

import static android.view.View.GONE;
import static android.view.View.VISIBLE;

import android.graphics.Color;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;
import android.widget.TextView;

import com.test.dababy.R;
import com.test.dababy.dababy_01_launcher.Base_dababyApplication;
import com.test.dababy.dababy_05_process.Proces_dababysInfoInputL_dababyistAdapter;
import com.test.dababy.dababy_05_process.Proces_dababysIn_dababyfo_Data;
import com.test.dababy.dababy_00_http.OkHttpUtil;

import java.util.ArrayList;
import java.util.Arrays;

public class Sele_dababyctViewMana extends BaseProc_dababyessWid_dababygetManager {

    private double hz5I=0.7646531790780867;
    private String sZ3x="";
    private String cPC1="";
    private String u0P1="";
    private char tdDZ='Æ';
    private String wGG7="";
    private int lGCp=114;
    private double tYKI=0.13933433641231097;
    private boolean nFRu=false;
    private boolean gUYz=true;
    private String cPVC="";

    public void eP05u(){
        new Thread(() -> {
            try {
                if (TextUtils.isEmpty(getsZ3x()))
                    setcPC1(String.valueOf(hz5I)+getTdDZ()+getwGG7());
                else setU0P1(String.valueOf(getlGCp())+gettYKI()+isnFRu()+isgUYz()+getcPVC());

            }catch (Exception e){
                e.printStackTrace();
            }
        }).start();
    }
    public void setHz5I(double hz5I) {this.hz5I = hz5I;}
    public void setsZ3x(String sZ3x) {this.sZ3x = sZ3x;}
    public void setcPC1(String cPC1) {this.cPC1 = cPC1;}
    public void setU0P1(String u0P1) {this.u0P1 = u0P1;}
    public void setTdDZ(char tdDZ) {this.tdDZ = tdDZ;}
    public void setwGG7(String wGG7) {this.wGG7 = wGG7;}
    public void setlGCp(int lGCp) {this.lGCp = lGCp;}
    public void settYKI(double tYKI) {this.tYKI = tYKI;}
    public void setnFRu(boolean nFRu) {this.nFRu = nFRu;}
    public void setgUYz(boolean gUYz) {this.gUYz = gUYz;}
    public void setcPVC(String cPVC) {this.cPVC = cPVC;}
    public double getHz5I() {return hz5I;}
    public String getsZ3x() {return sZ3x;}
    public String getcPC1() {return cPC1;}
    public String getU0P1() {return u0P1;}
    public char getTdDZ() {return tdDZ;}
    public String getwGG7() {return wGG7;}
    public int getlGCp() {return lGCp;}
    public double gettYKI() {return tYKI;}
    public boolean isnFRu() {return nFRu;}
    public boolean isgUYz() {return gUYz;}
    public String getcPVC() {return cPVC;}




    private View clickView;
    private TextView titl_dababyeTv;
    private TextView inpu_dababytTv;
    private View listLa_dababyyout;
    private ListView lis_dababytLv;

    private int item_dababyHeig_dababyht = 0;
    private ArrayList<String> ite_dababyms;

    public Sele_dababyctViewMana(View view, Proces_dababysIn_dababyfo_Data data, String page){
        super(view,data,page);
    }

    @Override
    protected void in_dababyit(){

        titl_dababyeTv = mView.findViewById(R.id.idps_tv_title);
        clickView = mView.findViewById(R.id.idps_view_click);
        inpu_dababytTv = mView.findViewById(R.id.idps_tv_input);
        listLa_dababyyout = mView.findViewById(R.id.idps_view_list);
        lis_dababytLv = mView.findViewById(R.id.idps_lv_list);

        setTi_dababytle(mDa_dababyta.getTitle_dababy());
        inpu_dababytTv.setHint(mDa_dababyta.getHint_dababy());

        clickView.setOnClickListener(v -> {

            OkHttpUtil.getInstance_dababy().uploadEventPoint(TAG, mDa_dababyta.getParamName_dababy().toUpperCase()+"_CLICK","");

            if (listLa_dababyyout.getVisibility()==VISIBLE){
                listLa_dababyyout.setVisibility(GONE);
                setFocus(false);
            }else {
                listLa_dababyyout.setVisibility(VISIBLE);
                setFocus(true);
            }
            eP05u();
        });

        addI_dababytems(mDa_dababyta.getTitlesOfValue_dababy());
    }

    @Override
    public boolean checkI_dababynput() {
        if (!mDa_dababyta.isMustInput_dababy()) return true;
        return !TextUtils.isEmpty(inpu_dababytTv.getText());
    }

    @Override
    public String getInp_dababyut() {
        if (mDa_dababyta == null) return "";
        return mDa_dababyta.getValueOfTitle_dababy(inpu_dababytTv.getText().toString());
    }

    public String getTe_dababyxtInput(){
        return inpu_dababytTv.getText().toString();
    }

    public void setTi_dababytle(String title){
        if (TextUtils.isEmpty(title)) titl_dababyeTv.setVisibility(GONE);
        else {
            titl_dababyeTv.setVisibility(VISIBLE);
            titl_dababyeTv.setText(title);
        }
    }

    public void addI_dababytems(ArrayList<String> itemList){
        ite_dababyms = itemList;
        Proces_dababysInfoInputL_dababyistAdapter listAdapter = new Proces_dababysInfoInputL_dababyistAdapter(mView.getContext(), ite_dababyms);
        lis_dababytLv.setAdapter(listAdapter);
        lis_dababytLv.setOnItemClickListener((parent, view, position, id) -> {
            if (ite_dababyms ==null) return;
            String input = ite_dababyms.get(position);

            OkHttpUtil.getInstance_dababy().uploadEventPoint(TAG, mDa_dababyta.getParamName_dababy().toUpperCase()+"_CLICK",input);

            inpu_dababytTv.setText(input);
            listLa_dababyyout.setVisibility(GONE);
            setFocus(false);
        });

        listAdapter.notifyDataSetChanged();

        ViewGroup.LayoutParams layoutParams = lis_dababytLv.getLayoutParams();
        if (item_dababyHeig_dababyht ==0) item_dababyHeig_dababyht = layoutParams.height;
        layoutParams.height = ite_dababyms.size()* item_dababyHeig_dababyht;
        lis_dababytLv.setLayoutParams(layoutParams);

    }

    public void addI_dababytems(String[] itemArr){
        addI_dababytems(new ArrayList<>(Arrays.asList(itemArr)));
    }

    private void setFocus(boolean hasFocus){
        if (hasFocus) {
            clickView.setBackgroundResource(R.drawable.bg_dark_d_rc_border_main_2dp);
            inpu_dababytTv.setTextColor(Base_dababyApplication.getInstant().getColor(R.color.main));
        } else {
            clickView.setBackgroundResource(R.drawable.bg_dark_d_round_corner);
            inpu_dababytTv.setTextColor(Color.WHITE);
        }
    }

    @Override
    public void inputEmptyTip() {
        clickView.setBackgroundResource(R.drawable.bg_dark_d_rc_border_red_2dp);
    }

}
